package tron.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import tron.config.RedisConfigProperties;
import tron.service.TronRedisService;

@RestController
public class RedisServiceController {

    @Autowired
    TronRedisService redisService;

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired(required = false)
    RedisConfigProperties redisConfigProperties;

    @GetMapping("/test")
    public Object test() {
        System.out.println("=======线程执行======="+Thread.currentThread().getId());
//        System.out.println(redisConfigProperties.getRedis());
        final RedisConnectionFactory connectionFactory = redisTemplate.getConnectionFactory();
        System.out.println(connectionFactory.toString());
        redisTemplate.opsForValue().setIfAbsent("test", 0);
        Integer test = (Integer) redisTemplate.opsForValue().get("test");
        test+= 1;
        redisTemplate.opsForValue().set("test",test);
        return test;
    }
}
